package edu.biwu.response;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.util.Date;

/**
 *  HttpServletResponse中的方法
 *     void setHeader(String var1, String var2):可以设置响应头，一个key只会对应一个value，新的value值会覆盖老的value值(类似HashMap)
 *
 *     void addHeader(String var1, String var2):可以添加响应头，一个key可以对应多个value值
 *
 *     public void setDateHeader(String name, long date):设置一个日期相关的响应头
 */
@WebServlet("/resp/demo02")
public class ResponseDemo02 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.addHeader("name","zhangsan");
        response.addHeader("gender","male");
        response.addHeader("name","lisi");

        response.setHeader("name","wangwu");//这个name会覆盖上边的name值
        response.setDateHeader("date", new Date().getTime());

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
